##
# This class handles the gradebook for the students.
class GradebookController < ApplicationController
	helper :paginator
	helper :right
  helper :gradebook
	include PaginatorHelper
	include RightHelper
  include GradebookHelper
	layout 'scaffold'

  # verifies that the logged in user has student-rights
	before_filter :verify_student

  ##
  # this method redirects to the list-method
	def index
		list
		render :action => 'list'
	end
	
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  # verify that an active session exists
	verify :session => 'user',
				 :redirect_to => { :controller => 'user', :action => :login },
				 :add_flash => {:error => 'you must be logged in to create activations'}

  ##
  # lists all taken exams from the corresponding user
	def list
    @exams = ExamResult.find(:all, :conditions => { :user_id => 
                                                    session['user'].id })
		@exam_pages, @exams = paginate_collection @exams, :per_page => 10, 
                                                      :page => params[:page]
	end

  ##
  # shows one exam with his answers
	def show
		@exam = ExamResult.find(params[:id])
    @user_answers = find_user_answers(@exam.exam, session['user'])
	end
end
